package com.yy.micro.magic.data.rest;

import com.yy.micro.magic.data.domain.DynamicTriggerVo;
import com.yy.micro.magic.data.service.trigger.MagicTriggerService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("magic-cube/data/trigger")
public class DynamicTriggerRestful {

    @Autowired
    private MagicTriggerService service;
    @PostMapping("save")
    public DynamicTriggerVo save(@RequestBody DynamicTriggerVo request){
        return service.apply(request);
    }

    @GetMapping("find/{planCode}")
    public List<DynamicTriggerVo> findByPlan(@PathVariable  String planCode){
        return service.find(planCode);
    }

    @GetMapping("load/{id}")
    public DynamicTriggerVo load(@PathVariable  Long id){
        return service.load(id);
    }

    @GetMapping("find/{planCode}/{trigger}")
    public DynamicTriggerVo findByPlanAndTrigger(@PathVariable  String planCode,@PathVariable String trigger){
        return service.find(planCode,trigger);
    }
}
